#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
	if (argc != 3) {
		printf("appkmem [size] [count]\n");
		return 0;
	}

	int size  = atoi(argv[1]);
	int count = atoi(argv[2]);

	int fd = open("/dev/kmem", O_RDWR);
	if (fd < 0) {
		printf("open error\n");
		return -1;
	}

	int ret;
	for (int i = 0; i < count; i++) {
		ret = ioctl(fd, 1, size);
		if (ret != 0) {
			printf("ioctl error\n");
			break;
		}
	}

	printf("done.\n");
	getchar();

	close(fd);

	return 0;
}
